Repository navigation
feat(ourlogs): Show all log details when expanding a row - #86240
Conversation
This adds the EventsTagTree like behaviour that queries and shows all log details when opening a row.
Bundle ReportChanges will increase total bundle size by 42.3MB (100.0%) ⬆️
|
| export function useExploreLogsTableRow(_props: { | ||
| log_id: string | number; | ||
| project_id: string; | ||
| enabled?: boolean; | ||
| }) { | ||
| const organization = useOrganization(); | ||
| const {projects} = useProjects(); | ||
| const _project = projects.find(p => p.id === _props.project_id); | ||
|
|
||
| const {data, isError, isPending} = useQuery<OurLogsTableRowDetails>({ | ||
| queryKey: ['logs-table-row', _props.log_id, _props.project_id], | ||
| queryFn: async () => { | ||
| if (!_project) { | ||
| throw new Error('Project not found'); | ||
| } | ||
| const res = await fetch( | ||
| `/api/0/projects/${organization.slug}/${_project?.slug}/trace-items/${_props.log_id}/?dataset=ourlogs` | ||
| ); | ||
| if (!res.ok) { | ||
| throw new Error('Failed to fetch log details'); | ||
| } | ||
| return await res.json(); | ||
| }, | ||
| }); |
There was a problem hiding this comment.
Hey @k-fish @colin-sentry 👋
I’m currently in the process of turning on the eslint-plugin-query, which contains lint rules for using react query.
I got some violations reported here because not everything that we use inside the queryFn is also part of the query key. It’s essential to keep those “dependencies” in sync with the query key, which is why the rule exists.
I don’t know enough about how this specific query is used, so I’ve just disabled the linter for now (see here), but I would appreciate a follow-up here.
Specifically, I’ve noticed a couple of things:
enabledcan be passed as an option (which is also done at one call-side), but it’s not forwarded touseQuery.- the check for
!_projectseems to be a “this should never happen case”, so maybe, we should rather disable the query too if that’s the case? - for a type-safe way to do disabling, react-query offers a skipToken that can be used instead of the
queryFn. - I think this is the only place that uses
fetchdirectly rather than our apiClient. Not sure if this is on purpose, but I think the best way to use react-query with our apiClient is either viauseApiQuerydirectly, or by usingfetchDataQueryas thequeryFn.
I’m happy to contribute here or jump on a quick sync to discuss this if you want.
There was a problem hiding this comment.
Yeah that's all fine, I'm replacing this anyway, just wrote it quickly for log details. I'll address these comments then.
Summary
This adds the EventsTagTree like behaviour that queries and shows all log details when opening a row. Once we figure out the rest of the EAP items tables / detail views we can make a generic component.
Blocked on #86235 to replace the mock data in the hook with an actual backend call.
Screenshots